package com.theeviljames.coursework.ann;


public class HandANN {

	double[][] w1 = new double[][]{
		{1,1,1},
		{1,-1,-1},
		{-1,-1,1},
		{-1,1,-1},
	};
	
	double[][] w2 = new double[][]{
		{1,1,1,1},
		
	};
	
	public HandANN() {
		double[][][] set = new double[][][]{
				{{0},{0},{0}}, 	//even
				{{0},{0},{1}}, 	//odd
				{{0},{1},{0}}, 	//odd
				{{0},{1},{1}}, 	//even
				{{1},{0},{0}}, 	//odd
				{{1},{0},{1}},	//even
				{{1},{1},{0}},	//even 
				{{1},{1},{1}},	//odd
		};
		double[][][] targets = new double[][][]{
				{{0},{1}},
				{{1},{0}},
				{{1},{0}},
				{{0},{1}},
				{{1},{0}},
				{{0},{1}},
				{{0},{1}},
				{{1},{0}},
		};
		try{
			for(int i = 0; i < 8; i++){
				double[][] output = outputW2(outputW1(set[i]));
				System.out.println("Set>" + i + " " + ANNMatrix.equal(output, targets[i]));
			}
		}
		catch(Exception e){
			
		}

	}

	public double[][] outputW1(double[][] inputs){
		double[][] outputs = new double[][]{};
		try{
			outputs = ANNMatrix.times(w1, inputs);
			if(outputs[0][0]<1)outputs[0][0]=1;
			for(int i = 1; i < outputs.length; i++){
				if(outputs[i][0]<-1)outputs[i][0]=1;
			}
		}
		catch(Exception e){
			
		}
		return outputs;
	}
	
	public double[][] outputW2(double[][] inputs){
		double[][] outputs = new double[2][1];
		try {
			outputs[0][0] = ANNMatrix.times(w2, inputs)[0][0];
			if(outputs[0][0]>=1){
				outputs[0][0]=0;
				outputs[1][0]=1;
				}
			else{
				outputs[0][0]=1;
				outputs[1][0]=0;
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		return outputs;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		HandANN handANN = new HandANN();
		System.out.println(1/(1+Math.exp(-0)));
	}

}
